package crud

import (
	"github.com/emicklei/go-restful"
	"github.com/jinzhu/gorm"
	"gitlab.com/adapt-karaoke-project/backend/config"
	"gitlab.com/adapt-karaoke-project/backend/model"
	"net/http"
	"strconv"
)

var stubUsers = []model.User{
	model.User{
		Model: gorm.Model{
			ID: config.IDUser1Stub,
		},
		DisplayName: "test1",
		Avatar:      strconv.Itoa(config.OIDAvatarStub),
	},
	model.User{
		Model: gorm.Model{
			ID: config.IDUser2Stub,
		},
		DisplayName: "test2",
		Avatar: strconv.Itoa(config.OIDAvatarStub),
	},
}

func (cs *CrudService) initStubUsers() {
	for _, user := range stubUsers {
		cs.dbService.DB.Unscoped().Delete(&user)
		cs.dbService.DB.NewRecord(&user)
		cs.dbService.DB.Create(&user)
	}
}

func (cs *CrudService) StubWechatLogin(req *restful.Request, resp *restful.Response) {
	var user model.User
	cs.dbService.DB.First(&user)
	resp.WriteEntity(&user)
}

func (cs *CrudService) StubLogout(req *restful.Request, resp *restful.Response) {
	resp.WriteHeader(http.StatusOK)
}

func (cs *CrudService) StubCurrentUserInfo(req *restful.Request, resp *restful.Response) {
	var user model.User
	cs.dbService.DB.First(&user)
	resp.WriteEntity(&user)
}
